/**
 * Framework for batch testing user profile models
 * Final project by Sergey Nepomnyachiy and Julia Polchin
 * Supervisor: Tsvi Kuflik
 *
 */
package core.generators;

import interfaces.GeneratorInterface;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * Same as ints set - creates a set of ints from given string, but this one
 * shuffles them
 * 
 * @author Sergey&Julia
 * 
 */
public class RandomIntSetGenerator implements GeneratorInterface<Integer> {
	protected List<Integer> set;

	/**
	 * Set constructor from string with delimiters
	 * 
	 * @param set
	 *            values list delimited by delimiter
	 * @param delimiter
	 *            delimiting sequence of set string
	 * 
	 *            !!! Be aware that the delimiter must no be the same as decimal
	 *            sign ( dot, coma ) Check your regional setting, if you see the
	 *            tests fail
	 * @param seed Seed the random generator for shuffling
	 * 
	 */
	@SuppressWarnings("boxing")
	public RandomIntSetGenerator(String set, String delimiter, long seed) {
		this.set = new ArrayList<Integer>();
		for (String s : set.split(delimiter)) {
			this.set.add(Integer.parseInt(s));
		}
		Random r = new Random(seed);
		Collections.shuffle(this.set, r);
	}

	/**
	 * Getter for the first scalar value
	 * 
	 * @return Number that is the first Integer in the set
	 */
	@Override
	public Integer getScalar() {
		return this.set.iterator().next();
	}

	/**
	 * Getter for the whole set of Integers
	 * 
	 * @return Integers from set
	 */
	@Override
	public Collection<Integer> getVector() {
		return this.set;
	}

	@Override
	public boolean is2D() {
		return false;
	}

}
